package com.demo;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.Arrays;
import java.util.List;


public class UnitTestUtils {
	private static final Logger logger = Logger.getLogger(UnitTestUtils.class);
	
	public static void initializeDatabase(DataSource ds, String[] sqls) {
		logger.info(StringUtils.join(sqls, "\n"));
		List<String> nonEmptySqls = Arrays.asList(sqls);
		JdbcTemplate template = new JdbcTemplate(ds);
		template.batchUpdate(nonEmptySqls.toArray(new String[0]));

	}
}
